<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/17 0017
  Time: 下午 3:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<form class="layui-form" action="/shop/saveHotCommodity">
    <input name="id" value="${record.id}" type="hidden">


    <c:choose>
        <c:when test="${ empty record}">
            <div class="layui-form-item">
                <label class="layui-form-label">礼品卡</label>
                <div class="layui-input-block">
                        <%--<select name="id" id ="selectTest" lay-verify="" lay-search>--%>
                        <%--<c:forEach items="${commodityList}" var="commodity">--%>
                        <%--<option value="${commodity.id}">${commodity.name}--%>
                        <%--<c:choose>--%>
                        <%--<c:when test="${commodity.type==0}">(PC商品)</c:when>--%>
                        <%--<c:when test="${commodity.type==1}">(移动端)</c:when>--%>
                        <%--<c:when test="${commodity.type==2}">（小程序）</c:when>--%>
                        <%--<c:when test="${commodity.type==3}">（支付宝）</c:when>--%>
                        <%--<c:when test="${commodity.type==4}">（抖音）</c:when>--%>
                        <%--<c:otherwise></c:otherwise>--%>
                        <%--</c:choose>--%>
                        <%--</option>--%>
                        <%--</c:forEach>--%>
                        <%--</select>--%>
                    <select name="id" id="selectTest" lay-search>

                    </select>

                </div>
            </div>
        </c:when>
        <c:otherwise>
            <div class="layui-form-item">
                <label class="layui-form-label">回收卡</label>
                <div class="layui-input-block">
                    <input type="text" name="hotNumber" required
                           disabled="disabled" autocomplete="off" class="layui-input" value="${record.name}">
                </div>
            </div>

        </c:otherwise>
    </c:choose>


    <div class="layui-form-item">
        <label class="layui-form-label">热度序号</label>
        <div class="layui-input-block">
            <input type="number" name="hotNumber" required lay-verify="required|number"
                   placeholder="请输入名称" autocomplete="off" class="layui-input" value="${record.hotNumber}">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <%--<button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
        </div>
    </div>
</form>
<script>
    layui.use('form', function () {
        var form = layui.form;
        $.ajax({
            url: '/shop/getCommodityListForHot',
            type: 'POST', //GET
            async: false,    //或false,是否异步

            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
            },
            success: function (dataA) {
                var child = $('#selectTest');
                var html ;
                dataA.forEach(function (item, index) {
                    html += "<option  value='" + item.id + "'>" + item.name + item.typeName + "</option>";
                });
                child.html(html);
                layui.use('form', function () {
                    form = layui.form;
                    form.render("select");
                });

            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                //console.log('结束')
            }
        });
    });

</script>
<script>
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: '/shop/saveHotCommodity',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: data.field,
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success: function (data) {
                    console.log(data);
                    if (data.code == '000000') {
                        layer.msg(data.msg, {time: 1000, icon: 6}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                        // 获得frame索引

                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 5});
                    }
                    //console.log(data)
                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete: function () {
                    //console.log('结束')
                }
            });
            return false;
        });
    });
</script>


</body>
</html>
